home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / TVDMX / FILEDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1994-06-20  |  6KB  |  249 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    FILEDEMO  --Buffered File Editing Demo        }
  5. {    tvDMX      --data editing project        }
  6. {                            }
  7. {    Copyright (c) 1993  Randolph Beck        }
  8. {                P.O. Box  56-0487        }
  9. {                Orlando, FL 32856        }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {    This program demonstates how to use tvDMX    }
  13. {    with regular Pascal files.  See FILESHOP.PAS    }
  14. {    to work with streams.                }
  15. {                            }
  16. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  17.  
  18. Program FILEDEMO;
  19.  
  20. {$M 16384,8192,655360 }
  21. {$B-,I-,R-,X+,V- }
  22.  
  23. uses  Objects, Drivers, Views, Menus, App, MsgBox,
  24.       RSet, DmxGizma, tvGizma, tvDMX, tvDMXBUF, tvDMXREP;
  25.  
  26. const
  27.     xLabel    =  ' Name                     Debit       Credit     mm-dd-yyyy ';
  28.     xTemplate    =  ' ssssssssssssssssssss║($rr,rrr.zz)|($rr,rrr.zz)|' + fldDATE;
  29.  
  30.     MyLabel    :  string[length(xLabel)]    = xLabel;
  31.     MyTemplate    :  string[length(xTemplate)]    = xTemplate;
  32.  
  33.     cmOpenWin    =  101;
  34.     cmPrint    =  102;
  35.  
  36.  
  37. type
  38.     DataRec    =  RECORD
  39.     S    : array[1..20] of char;
  40.     R1,R2    : TRealNum;
  41.     Date    : array[1..8] of char;
  42.     end;
  43.  
  44.     DataFile     =  file of DataRec;
  45.  
  46.     PDmxDataFile  = ^TDmxDataFile;
  47.     TDmxDataFile     =  OBJECT(TDmxEditBuf)
  48.     ErrorInfo    : word;
  49.       function    RecordLimit : longint;    VIRTUAL;
  50.       function    SeekRec(RecNum : longint) : boolean;  VIRTUAL;
  51.       function    SeekEnd : boolean;  VIRTUAL;
  52.       function    ReadRec(var RecData ) : boolean;  VIRTUAL;
  53.       function    WriteRec(var RecData ) : boolean;  VIRTUAL;
  54.     end;
  55.  
  56.  
  57.     TAppN      =  OBJECT(TAppA)
  58.     end;
  59.  
  60.     TMyApp      =  OBJECT(TAppN)
  61.       constructor Init;
  62.       destructor  Done;  VIRTUAL;
  63.       procedure HandleEvent(var Event: TEvent);  VIRTUAL;
  64.       procedure InitMenuBar;  VIRTUAL;
  65.       procedure OpenWindow;
  66.       function    OpenFile(var F : DataFile;  FName : string)  : boolean;
  67.       procedure CloseFile(var F : DataFile);
  68.     end;
  69.  
  70.  
  71. var
  72.     WorkFile    :  DataFile;
  73.  
  74.  
  75.   { ══ TDmxDataFile ══════════════════════════════════════════════════════ }
  76.  
  77.  
  78. function  TDmxDataFile.RecordLimit : longint;
  79. begin
  80.   RecordLimit := FileSize(DataFile(WorkingData^));
  81.   ErrorInfo := IOResult;
  82. end;
  83.  
  84.  
  85. function  TDmxDataFile.SeekRec(RecNum : longint) : boolean;
  86. begin
  87.   Seek(DataFile(WorkingData^), RecNum);
  88.   ErrorInfo := IOResult;
  89.   SeekRec := (ErrorInfo = 0);
  90. end;
  91.  
  92.  
  93. function  TDmxDataFile.SeekEnd : boolean;
  94. begin
  95.   SeekEnd := SeekRec(RecordLimit);
  96. end;
  97.  
  98.  
  99. function  TDmxDataFile.ReadRec(var RecData ) : boolean;
  100. begin
  101.   Read(DataFile(WorkingData^), DataRec(RecData));
  102.   ErrorInfo := IOResult;
  103.   ReadRec := (ErrorInfo = 0);
  104. end;
  105.  
  106.  
  107. function  TDmxDataFile.WriteRec(var RecData ) : boolean;
  108. begin
  109.   Write(DataFile(WorkingData^), DataRec(RecData));
  110.   ErrorInfo := IOResult;
  111.   WriteRec := (ErrorInfo = 0);
  112. end;
  113.  
  114.  
  115.   { ══ TMyApp ════════════════════════════════════════════════════════════ }
  116.  
  117.  
  118. constructor TMyApp.Init;
  119. begin
  120.   TAppN.Init;
  121.  
  122.   If not OpenFile(WorkFile, 'FILEDEMO.DAT') then
  123.     begin
  124.     DisableCommands([cmOpenWin]);
  125.     MessageBox('Error initializing file.', nil, mfError + mfOKButton);
  126.     end;
  127.  
  128. end;
  129.  
  130.  
  131. destructor TMyApp.Done;
  132. begin
  133.   TAppN.Done;
  134.   CloseFile(WorkFile);
  135. end;
  136.  
  137.  
  138. procedure TMyApp.HandleEvent(var Event: TEvent);
  139. begin
  140.   TAppN.HandleEvent(Event);
  141.   If Event.What = evCommand then
  142.     begin
  143.     Case Event.Command of
  144.       cmOpenWin    : OpenWindow;
  145.       cmPrint    : PrnCurrentDMX;
  146.      else
  147.       Exit;
  148.       end;
  149.     ClearEvent(Event);
  150.     end;
  151. end;
  152.  
  153.  
  154. procedure TMyApp.InitMenuBar;
  155. var  R: TRect;
  156. begin
  157.   GetExtent(R);
  158.   R.B.Y := R.A.Y + 1;
  159.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  160.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  161.       NewItem('~O~pen',    'F4',   kbF4,   cmOpenWin,    hcNoContext,
  162.       NewItem('~P~rint',   'F9',   kbF9,   cmPrint,    hcNoContext,
  163.       NewLine(
  164.       NewSoundItem(hcNoContext,
  165.       NewVideoItem(hcNoContext,
  166.       NewLine(
  167.       NewItem('e~X~it',  'Alt-X',  kbAltX, cmQuit,    hcNoContext,
  168.       nil)))))))),
  169.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  170.       NewItem('~S~ize/Move', 'Ctrl-F5', kbCtrlF5, cmResize, hcNoContext,
  171.       NewItem('~Z~oom',      'F5',  kbF5,    cmZoom,    hcNoContext,
  172.       NewItem('~T~ile',      '',    kbNoKey, cmTile,    hcNoContext,
  173.       NewItem('C~a~scade',   '',    kbNoKey, cmCascade, hcNoContext,
  174.       NewItem('~N~ext',      'F6',  kbF6,    cmNext,    hcNoContext,
  175.       NewItem('~P~revious', 'Shift-F6', kbShiftF6, cmPrev, hcNoContext,
  176.       NewItem('~C~lose', 'Alt-F3',  kbAltF3, cmClose,    hcNoContext,
  177.       NewLine(
  178.       NewItem('~U~ser screen', 'Alt-F5',  kbAltF5, cmUserScreen, hcNoContext,
  179.       nil)))))))))),
  180.     nil)))
  181.   ));
  182. end;
  183.  
  184.  
  185. procedure TMyApp.OpenWindow;
  186. var  R    : TRect;
  187.      W    : PWindow;
  188.      DMX: PDmxDataFile;
  189. begin
  190.   AssignWinRect(R, length(MyLabel) + 2, 0);  { assign window dimensions }
  191.       { width of string MyLabels plus two for the border; }
  192.       { zero rows indicates extend to bottom of screen }
  193.  
  194.   New(W, Init(R, 'Data Window', wnNextAvail));
  195.   With W^ do
  196.     begin
  197.     Options := Options or ofTileable; { must be tileable for AssignWinRect }
  198.     GetExtent(R);          { create new rectangle for editor object }
  199.     R.Grow(-1,-1);                  { shrink -1 to avoid borders }
  200.     Inc(R.A.Y, 2);             { make room for TDmxLabels object }
  201.     New(DMX, Init(MyTemplate,                 { template string }
  202.         WorkFile,                    { working data }
  203.         0,             { irrelevant if you use ResetSize }
  204.         R,                    { view's rectangle }
  205.         New(PDmxLabels, InitInsert(W, @MyLabel)), { label string }
  206.         New(PDmxExpRecInd, InitInsert(W, 10)), { indicator width }
  207.         StandardScrollBar(sbHandleKeyboard or sbHorizontal),
  208.         StandardScrollBar(sbHandleKeyboard or sbVertical)
  209.         )
  210.     );
  211.     DMX^.Expandable := TRUE;    { allows more records to be added }
  212.     DMX^.ResetSize;        { reset DataBlockSize and Limits }
  213.     Insert(DMX);
  214.     end;
  215.   DeskTop^.Insert(ValidView(W));
  216. end;
  217.  
  218.  
  219. function  TMyApp.OpenFile(var F : DataFile;  FName : string) : boolean;
  220. var  Err : word;
  221. begin
  222.   Assign(F, FName);
  223.   Reset(F);
  224.   Err := IOResult;
  225.   If (Err <> 0) then
  226.     begin
  227.     ReWrite(F);
  228.     Err := IOResult;
  229.     end;
  230.   OpenFile := (Err = 0);
  231. end;
  232.  
  233.  
  234. procedure TMyApp.CloseFile(var F : DataFile);
  235. begin
  236.   Close(F);
  237. end;
  238.  
  239.  
  240.   { ══════════════════════════════════════════════════════════════════════ }
  241.  
  242. var  MyApp    :  TMyApp;
  243.  
  244. Begin
  245.   MyApp.Init;
  246.   MyApp.Run;
  247.   MyApp.Done;
  248. End.
  249.